package com.fand.manager.model.role;

import java.util.Objects;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.fand.common.annotation.DataField;
import com.fand.common.enums.ConditionOnField;
import com.fand.common.model.BaseDTO;
import com.fand.common.util.JsonUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * Author: zhangjiabin
 * Email: javaboyok@163.com
 * CreateDate: 2021/6/3
 * Version: 1.0
 */
@Data
public class SysRoleSearchDTO extends BaseDTO {

    @ApiModelProperty(value = "角色名称")
    @DataField(tableFiled = "name",condition = ConditionOnField.LIKE_RIGHT)
    private String name;

    @ApiModelProperty(value = "角色编码")
    @DataField(tableFiled = "code",condition = ConditionOnField.LIKE_RIGHT)
    private String code;

    public SysRoleSearchDTO builder() {
        if (Objects.isNull(getSearchParams())) {
            return this;
        } else {
            SysRoleSearchDTO sysRoleSearchDTO = JsonUtils.jsonToPojo(JsonUtils.objectToJson(JsonUtils.jsonToPojo(getSearchParams(), SysRoleSearchDTO.class)), SysRoleSearchDTO.class);
            CopyOptions copyOptions = CopyOptions.create();
            copyOptions.setIgnoreNullValue(true);
            BeanUtil.copyProperties(sysRoleSearchDTO,this, copyOptions);
            return this;
        }
    }
}
